/*
 * Copyright (C) 2020 ~ 2022 Uniontech Software Technology Co.,Ltd.
 *
 * Author:     Zhang Qipeng <zhangqipeng@uniontech.com>
 *
 * Maintainer: Zhang Qipeng <zhangqipeng@uniontech.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "black_widget.h"

#include <QPainter>

BlackWidget::BlackWidget(QWidget *parent)
    : QWidget(parent)
    , m_cursor(cursor())
{
    setObjectName(QStringLiteral("BlackWidget"));
    setAccessibleName(QStringLiteral("BlackWidget"));
}

void BlackWidget::setBlackMode(const bool isBlackMode)
{
    setVisible(isBlackMode);
#ifndef QT_DEBUG
    setCursor(isBlackMode ? Qt::BlankCursor : m_cursor);
#endif
}

void BlackWidget::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    QRect rect(QPoint(0, 0), QSize(size() * devicePixelRatioF()));
    painter.fillRect(rect, Qt::black);

    QWidget::paintEvent(event);
}

void BlackWidget::showEvent(QShowEvent *event)
{
    raise();
    QWidget::showEvent(event);
}
